package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup
var mt sync.Mutex
var x = 0

func main() {
	test1()
}

func increment() {
	mt.Lock()
	x = x + 1
	mt.Unlock()
	wg.Done()
}

func test1() {
	for i := 0; i < 1000; i++ {
		wg.Add(1)
		go increment()
	}
	wg.Wait()
	fmt.Println("final value of x", x)
}
